package com.zhuozhou.jdyc.main.menu.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.base.BaseSearchActivity;
import com.zhuozhou.jdyc.bean.PopupWindowBean;
import com.zhuozhou.jdyc.main.main.viewmodel.MainViewModel;
import com.zhuozhou.jdyc.main.menu.fragment.JokeFragment;
import com.zhuozhou.jdyc.wight.popupWindow.LinearRecyclerViewPopupWindow;

import java.util.ArrayList;
import java.util.List;

/**
 * Create by CherishTang on 2020/3/27 0027
 * describe:
 */
public class TestSearchActivity extends BaseSearchActivity<MainViewModel> {
    private LinearRecyclerViewPopupWindow areaCodePopupWindow = null;
    private List<PopupWindowBean> areaCodeList = null;

    private LinearRecyclerViewPopupWindow rentPopupWindow = null;
    private List<PopupWindowBean> rentList = null;

    @Override
    public String setTitleBar() {
        return "搜索示例";
    }

    @Override
    public void initView() {
        areaCodeList = new ArrayList<>();
        areaCodeList.add(new PopupWindowBean(null,"全部"));
        areaCodeList.add(new PopupWindowBean(0,"经开区"));
        areaCodeList.add(new PopupWindowBean(1,"庐阳区"));
        areaCodeList.add(new PopupWindowBean(2,"政务区"));
        areaCodeList.add(new PopupWindowBean(3,"高新区"));
        areaCodeList.add(new PopupWindowBean(4,"滨湖区"));
        areaCodeList.add(new PopupWindowBean(5,"瑶海区"));
        areaCodeList.add(new PopupWindowBean(6,"包河区"));
        areaCodeList.add(new PopupWindowBean(7,"肥西县"));
        areaCodeList.add(new PopupWindowBean(8,"肥东县"));
        areaCodeList.add(new PopupWindowBean(9,"巢湖市"));
        addMenuView("区域",v ->{
            if (areaCodePopupWindow == null) {
                areaCodePopupWindow = new LinearRecyclerViewPopupWindow(areaCodeList, this, false, (popupWindow, parentSelectPosition, childrenSelectPosition) -> {
                    ((TextView) v).setText(areaCodeList.get(parentSelectPosition).getName());
                });
            }
            areaCodePopupWindow.showAsDropDown(binding.baseSearchView.llMenuOption);
        });
        rentList = new ArrayList<>();
        rentList.add(new PopupWindowBean(null,"全部"));
        rentList.add(new PopupWindowBean(0,"整租"));
        rentList.add(new PopupWindowBean(1,"合租"));
        addMenuView("出租方式",v ->{
            if (rentPopupWindow == null) {
                rentPopupWindow = new LinearRecyclerViewPopupWindow(rentList, this, false, (popupWindow, parentSelectPosition, childrenSelectPosition) -> ((TextView) v).setText(rentList.get(parentSelectPosition).getName()));
            }
            rentPopupWindow.showAsDropDown(binding.baseSearchView.llMenuOption);
        });
    }

    @Override
    public void initData(Bundle bundle) {
        setFragment(getSupportFragmentManager(), JokeFragment.instantiate(bundle), R.id.search_view_container);
    }
}
